#import "iPhotoGalleryAppDelegate.h"

@implementation iPhotoGalleryAppDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [window makeKeyAndVisible];
    thumbsViewController = [[ThumbsViewController alloc]
                            initWithDelegate:self];
    slideshowViewController = [[SlideshowViewController alloc]
                               initWithDelegate:self];
    navBar = [[UINavigationController alloc]
              initWithRootViewController:thumbsViewController];
    [window addSubview:navBar.view];
}

- (void)dealloc
{
    [navBar release];
    [slideshowViewController release];
    [thumbsViewController release];
    [window release];
    [super dealloc];
}

#pragma mark ThumbsViewControllerDelegate

- (int)thumbsViewControllerPhotosCount:(ThumbsViewController *)tvc
{
    return 30;
}

- (void)thumbsViewController:(ThumbsViewController *)tvc
    fetchPhotoAtIndex:(int)index
{
    UIImage *photo = [UIImage imageNamed:[NSString stringWithFormat:
                                          @"Photo%d.jpg", (index % 3) + 1]];
    [tvc fetchedPhoto:photo atIndex:index];
}

- (void)thumbsViewController:(ThumbsViewController *)tvc
    selectedPhotoAtIndex:(int)index
{
    [slideshowViewController showPhotoAtIndex:index];
    [navBar pushViewController:slideshowViewController animated:YES];
}

#pragma mark SlideshowViewControllerDelegate

- (int)slideshowViewControllerPhotosCount:(SlideshowViewController *)svc
{
    return 30;
}

- (void)slideshowViewController:(SlideshowViewController *)svc
    fetchPhotoAtIndex:(int)index
{
    UIImage *photo = [UIImage imageNamed:[NSString stringWithFormat:
                                          @"Photo%d.jpg", (index % 3) + 1]];
    [svc fetchedPhoto:photo atIndex:index];    
}

@end
